﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using App1AppHandler;

namespace Reborn_Server.App1AppHandler
{
    public class Spell_RestoreStamina : TargetSpell
    {
        public void Cast(CreatureBase myCreatureBase, int CastLevel, long CreatureGUID)
        {
            List<MapItem> MapItemsWithin12;
            if (base.InitializeCast(myCreatureBase, CastLevel, CreatureGUID, false, out MapItemsWithin12) == false)
                return;

            List<Character> CharactersInUpdateRange = new List<Character>();
            foreach (MapItem mapitem in MapItemsWithin12)
            {
                foreach (CreatureBase creaturebase in mapitem.CreaturesBases)
                {
                    if (creaturebase is Character)
                        CharactersInUpdateRange.Add((Character)creaturebase);
                }
            }

            int StaminaToAdd = (80 + SkillManager.AdjustForCombat(CastLevel / 2, 0, CastingCreatureWis / 2));
            TargetCreatureBase.Stamina = TargetCreatureBase.Stamina + StaminaToAdd;
            TargetCreatureBase.Update_Character();

            if (myCreatureBase is Character)
            {
                Character myCharacter = (Character)myCreatureBase;

                Message healMsg1 = new Message();
                healMsg1.CreatureID = myCharacter.CreatureID;
                healMsg1.Type = "spelldefense";
                healMsg1.Text = "You restore " + TargetCreatureBase.Name + "'s stamina! ("+ StaminaToAdd.ToString() + ")";
                
                myCharacter.AddMessage(healMsg1);
            }
            if (TargetCreatureBase is Character && TargetCreatureBase != myCreatureBase)
            {
                Character targetCharacter = (Character)TargetCreatureBase;

                Message healMsg1 = new Message();
                healMsg1.CreatureID = targetCharacter.CreatureID;
                healMsg1.Type = "spelldefense";
                healMsg1.Text = myCreatureBase.Name + " restores your stamina! ("+ StaminaToAdd.ToString() + ")";

                targetCharacter.AddMessage(healMsg1);
            }
            foreach (Character character in CharactersInUpdateRange)
            {
                //Play Sound
                if (Math.Abs(character.MapX - TargetCreatureBase.MapX) <= 8 && Math.Abs(character.MapY - TargetCreatureBase.MapY) <= 8)
                    character.PlaySound("Heal", TargetCreatureBase.MapX, TargetCreatureBase.MapY);
            }

        }
    }
}
